'use strict'

const titbit = require('titbit')
const pg=require('pg')
const app=new titbit()

let config=new pg.Pool({
  database:'xinyou',
  user:'liuxintong',
  password:'285023'
})

// app.get('/timeletter',async c=>{
//   let sql='select * from timeletter'
//   let res=await config.query(sql)
//   let result=res['rows'];
//   c.send(result)
// })

//插入数据
// app.post('/user',async c=>{
//   let sql='select * from users'
//   let r=await config.query(sql);
//   let uid=r['rows'].length+1;
//   let data=JSON.parse(c.body.toString())
//   config.connect().then(client=>{
//     client.query("insert into users(uid,uname,age) values($1::int,$2::varchar,$3::int)",[uid,data.name,data.age]).then(res=>{
//       console.log("成功")
//     })
//   })
// })

//更改数据
// app.put('/user',async c=>{
//   config.connect().then(client=>{
//     client.query("update users set age=$1 where uid=$2",[55,1]).then(res=>{
//       console.log(client.query('select * from users where uid=$1',[1]));
//     })
//   })
// })


//删除数据
app.delete('/user',async c=>{
  config.connect().then(client=>{
    client.query("delete from users where uid=$1",[1]).then(res=>{
      console.log("成功")
    })
  })
})

app.run(5990)
